package org.meetunexpectedly.entity.json;

import lombok.Data;
import lombok.ToString;
import org.springframework.util.ObjectUtils;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @Description:
 * @Author: pupil
 * @Date: 2024/08/19 下午 3:14
 */
@Data
@ToString
public class BodyJson implements Serializable {
    String id; // 唯一标识该审核任务的ID
    String status; // 审核状态
    ResultJson result; // 审核结果

    /**
     * 比较内容审核结果是否符合系统的审核力度
     * 分数比较看是否命中，分数是否在范围内
     *
     * @param min   最小值
     * @param max   最大值
     * @param value 值
     * @return true 命中  false 没有命中
     */
    public boolean compare(Double min, Double max, Double value) {
        return value >= min && value <= max;
    }

    /**
     * 违规检测
     * @param types
     * @param min 最小值
     * @param max 最大值
     * @return 分数命中返回true，不命中返回false
     */
    public boolean checkViolation(List<CutsJson> types, Double min, Double max) {
        for (CutsJson cutsJson : types) {
            if (!ObjectUtils.isEmpty(cutsJson.details)) {
                // 获取所有该审核结果详细内容
                for (DetailsJson detail : cutsJson.details) {
                    // 进行内容比较，查看分数是否在这个范围内
                    if (compare(min, max, detail.getScore())){
                        return true;
                    }
                }
            }
        }
        return false;
    }

    /**
     * 获取反恐内容
     * 视频和图片分开处理
     * @return
     */
    public List<CutsJson> getTerror(){
        TypeJson terror = result.getResult().getScenes().getTerror();
        if (!ObjectUtils.isEmpty(terror.getCuts())){
            return terror.getCuts();
        }

        CutsJson cutsJson = new CutsJson();
        cutsJson.setDetails(terror.getDetails());
        cutsJson.setSuggestion(terror.getSuggestion());
        return Collections.singletonList(cutsJson);
    }


    /**
     * 获取政治内容
     * 视频和图片分开处理
     * @return
     */
    public List<CutsJson> getPolitician(){
        final TypeJson politician = result.getResult().getScenes().getPolitician();
        if (!ObjectUtils.isEmpty(politician.getCuts())){
            return politician.getCuts();
        }

        final CutsJson cutsJson = new CutsJson();
        cutsJson.setDetails(politician.getDetails());
        cutsJson.setSuggestion(politician.getSuggestion());

        return Collections.singletonList(cutsJson);
    }

    /**
     * 获取低俗内容
     * 视频和图片分开处理
     * @return
     */
    public List<CutsJson> getPulp(){
        final TypeJson pulp = result.getResult().getScenes().getPulp();
        if (!ObjectUtils.isEmpty(pulp.getCuts())){
            return pulp.cuts;
        }

        final CutsJson cutsJson = new CutsJson();
        cutsJson.setDetails(pulp.getDetails());
        cutsJson.setSuggestion(pulp.getSuggestion());

        return Collections.singletonList(cutsJson);
    }
}
